import 'package:flutter/cupertino.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';
import 'package:kq_flutter_core_widget/widgets/image/kq_image.dart';
import 'package:kq_flutter_tv_widgets/config/kq_global.dart';
import 'package:kq_flutter_tv_widgets/resources/kq_images.dart';
import 'package:kq_flutter_tv_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_tv_widgets/widgets/divider/kq_divider.dart';
import 'package:kq_flutter_tv_widgets/widgets/permission/kq_permission_view.dart';

import '../../resources/images.dart';

///抽屉标题（title+optTitle+close）
class DrawerTitle extends StatelessWidget {
  ///左边标题（黑色）
  final String? title;

  ///右边操作标题（蓝色）
  final String? optTitle;

  ///标题大小，默认28sp，弹窗的大小，如果内部也需要使用，可以自己传大小
  final double? titleFontSize;

  ///操作标题大小，默认28sp，弹窗的大小，如果内部也需要使用，可以自己传大小
  final double? optTitleFontSize;

  ///是否显示右边操作标题
  final bool isShowOptTitle;

  ///是否显示关闭图标
  final bool isShowClose;

  ///是否显示删除图标
  final bool isShowDelete;

  ///高度，默认72.r，弹窗的高度，如果内部页面要使用，可以自己传高度。
  final double? height;

  ///关闭图标点击回调
  final VoidCallback? onCloseTap;

  ///右边操作标题点击回调
  final VoidCallback? onOptTitleTap;

  ///删除图标点击回调
  final VoidCallback? onDeleteTap;

  ///中间自定义view
  final Widget? customCenterWidget;

  ///背景色
  final Color? bgColor;

  ///是否有删除权限
  final bool hasDeletePermission;

  const DrawerTitle({
    super.key,
    this.title,
    this.optTitle,
    this.isShowOptTitle = false,
    this.isShowClose = true,
    this.onCloseTap,
    this.onOptTitleTap,
    this.isShowDelete = false,
    this.onDeleteTap,
    this.height,
    this.customCenterWidget,
    this.titleFontSize,
    this.optTitleFontSize,
    this.bgColor,
    this.hasDeletePermission = false,
  });

  @override
  Widget build(BuildContext context) {
    var result = Column(
      children: [
        Container(
          height: height ?? 72.r,
          alignment: Alignment.center,
          padding: EdgeInsets.only(
            left: 24.r,
            right: isShowOptTitle && !isShowClose && !isShowDelete ? 24.r : 7.r,
          ),
          color: KqThemeColors.bgDialog,
          child: Row(
            children: [
              Text(
                title ?? "",
                style: TextStyle(
                  fontSize: titleFontSize ?? 28.sp,
                  color: KqThemeColors.textBlack85,
                ),
              ),
              Expanded(child: customCenterWidget ?? Container()),
              Visibility(
                visible: isShowOptTitle,
                child: KqInkWell(
                  onTap: () {
                    onOptTitleTap?.call();
                  },
                  child: Text(
                    optTitle ?? "",
                    style: TextStyle(
                      fontSize: optTitleFontSize ?? 28.sp,
                      color: KqThemeColors.textBlue,
                    ),
                  ),
                ),
              ),
              Visibility(
                visible: isShowDelete,
                child: KqPermissionView(
                  hasPermission: hasDeletePermission,
                  child: KqInkWell(
                    onTap: () {
                      onDeleteTap?.call();
                    },
                    horizontalPadding: 17.r,
                    verticalPadding: 17.r,
                    child: KqImage.custom(
                      url: KqImages.commonIcDeleteH28,
                      imageType: ImageType.assets,
                      package: KqGlobal.packageName,
                      width: 28.r,
                      height: 28.r,
                    ),
                  ),
                ),
              ),
              Visibility(
                visible: isShowClose,
                child: KqInkWell(
                  onTap: () {
                    onCloseTap?.call();
                  },
                  horizontalPadding: 17.r,
                  verticalPadding: 17.r,
                  child: KqImage.custom(
                    url: Images.commonIcGuanbi,
                    imageType: ImageType.assets,
                    package: KqGlobal.packageName,
                    width: 32.r,
                    height: 32.r,
                    fit: BoxFit.contain,
                  ),
                ),
              ),
            ],
          ),
        ),
        const KqDivider(),
      ],
    );
    if (bgColor != null) {
      return Container(
        color: bgColor,
        child: result,
      );
    } else {
      return result;
    }
  }
}
